//
//  TechTableViewCell.m
//  LPSNews
//
//  Created by Ruan on 14-10-10.
//  Copyright (c) 2014年 LPS. All rights reserved.
//

#import "TechTableViewCell.h"
#import "UIImageView+WebCache.h"
@implementation TechTableViewCell

- (void)dealloc
{
    
    [_techMode release];
    [_techcellImageView release];
    [_techcellTitle release];
    [_techcellAccessibilityLabel release];
    
    [super dealloc];
}



- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        
        self.backgroundColor = [UIColor colorWithRed:249/255.0 green:249/255.0 blue:249/255.0 alpha:1.0];
        
        UIImageView *techcellImageView = [[UIImageView alloc] init];
        UILabel *techcellTitle = [[UILabel alloc] init];
        UILabel *techcellAccessibilityLabel = [[UILabel alloc] init];
        UIImageView *techcellSencondImageView = [[UIImageView alloc] init];
        UIImageView *techcellThreeImageView = [[UIImageView alloc] init];
        
        
        UIView *techBottomLine = [[UIView alloc] init];
        
        self.techcellImageView = techcellImageView;
        self.techcellTitle = techcellTitle;
        self.techcellAccessibilityLabel = techcellAccessibilityLabel;
        self.techBottomLine = techBottomLine;
        self.techcellSencondImageView = techcellSencondImageView;
        self.techcellThreeImageView = techcellThreeImageView;

        [self addSubview:techcellImageView];
        [self addSubview:techcellTitle];
        [self addSubview:techcellAccessibilityLabel];
        [self addSubview:techcellSencondImageView];
        [self addSubview:techcellThreeImageView];
        [self addSubview:techBottomLine];
        
        [techcellImageView release];
        [techcellTitle release];
        [techcellAccessibilityLabel release];
        [techBottomLine release];
        [techcellThreeImageView release];
        [techcellSencondImageView release];
    }
    return self;
}

- (void)setTechMode:(TechMode *)techMode
{
    _techMode = techMode;

    [self.techcellImageView sd_setImageWithURL:[NSURL URLWithString:_techMode.imgsrc] placeholderImage:[UIImage imageNamed:@"placeholderImage"] options:SDWebImageProgressiveDownload];

    // 判断是否为第一个ROW
    if (self.tableRow == 0) {
        // 第一个大图
        CGSize tempsize = CGSizeMake(320, 185);
        self.techcellImageView.frame = (CGRect){CGPointZero,tempsize};
        
        // 大图的文字
        self.techcellTitle.text = _techMode.title;
        self.techcellTitle.frame = CGRectMake(14,CGRectGetMaxY(self.techcellImageView.frame) + 1, [UIScreen mainScreen].bounds.size.width -20, 25);
        self.techcellTitle.font = [UIFont systemFontOfSize:12];
        
    } else if (_techMode.imgextra != nil) {
        //标题
        self.techcellTitle.frame =CGRectMake(10, 6.75, [UIScreen mainScreen].bounds.size.width, 20);
        self.techcellTitle.font = [UIFont systemFontOfSize:14];
        self.techcellTitle.text = _techMode.title;
        //第一张图
        self.techcellImageView.frame = CGRectMake(10, CGRectGetMaxY(self.techcellTitle.frame) + 6.75, 99, 69.5);
        //第二和第三张图
        self.techcellSencondImageView.frame = CGRectMake(CGRectGetMaxX(self.techcellImageView.frame) +2,  CGRectGetMaxY(self.techcellTitle.frame) + 6.75, 99, 69.5);
        [self.techcellSencondImageView sd_setImageWithURL:[NSURL URLWithString:[_techMode.imgextra[0] objectForKey:@"imgsrc"]]placeholderImage:[UIImage imageNamed:@"placeholderImage"] options:SDWebImageProgressiveDownload];
        
        self.techcellThreeImageView.frame = CGRectMake(CGRectGetMaxX(self.techcellSencondImageView.frame) +2, CGRectGetMaxY(self.techcellTitle.frame) + 6.75, 99, 69.5);
        
        [self.techcellThreeImageView sd_setImageWithURL:[NSURL URLWithString:[_techMode.imgextra [1] objectForKey:@"imgsrc"]]placeholderImage:[UIImage imageNamed:@"placeholderImage"] options:SDWebImageProgressiveDownload];
        //底部的线
        self.techBottomLine.backgroundColor = [UIColor colorWithRed:200/255.0 green:200/255.0 blue:200/255.0 alpha:1.0];
        self.techBottomLine.frame = CGRectMake(0,CGRectGetMaxY(self.techcellImageView.frame) + 10.5, [UIScreen mainScreen].bounds.size.width, 0.75);
    }else{
        
        // 左面图片
        CGPoint tempoint = CGPointMake(10, 9.75);
        CGSize size = CGSizeMake(88.64, 65);
        self.techcellImageView.frame = (CGRect){tempoint,size};
        self.techcellImageView.contentMode = UIViewContentModeScaleAspectFill;
        self.techcellImageView.clipsToBounds = YES;
        
        // 主标题
        self.techcellTitle.text = _techMode.title;
        self.techcellTitle.font = [UIFont systemFontOfSize:14.5];
        self.techcellTitle.frame = CGRectMake(CGRectGetMaxX(self.techcellImageView.frame) + 10, 10, [UIScreen mainScreen].bounds.size.width - 10 - CGRectGetMaxX(self.techcellImageView.frame), 20);
        
        
        // 内容标题
        self.techcellAccessibilityLabel.text = _techMode.digest;
        self.techcellAccessibilityLabel.frame = CGRectMake(CGRectGetMaxX(self.techcellImageView.frame) + 10, CGRectGetMaxY(self.techcellTitle.frame), [UIScreen mainScreen].bounds.size.width - 10 - CGRectGetMaxX(self.techcellImageView.frame) -10 ,50);
        self.techcellAccessibilityLabel.font = [UIFont systemFontOfSize:13];
        self.techcellAccessibilityLabel.textColor = [UIColor darkGrayColor];
        self.techcellAccessibilityLabel.numberOfLines = 0;
        self.techcellAccessibilityLabel.lineBreakMode = NSLineBreakByWordWrapping;
        self.techBottomLine.backgroundColor = [UIColor colorWithRed:200/255.0 green:200/255.0 blue:200/255.0 alpha:1.0];
        
        // 底部的线
        self.techBottomLine.frame = CGRectMake(0, CGRectGetMaxY(self.techcellImageView.frame)+ 9.75, [UIScreen mainScreen].bounds.size.width, 0.75);
    }

    
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
